#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e6 + 10, INF = 0x3f3f3f3f;

void solve()
{
    int n;
    cin >> n;
    long long up, down;
    long long ans = -1;
    up = down = 0;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
        int now = i + 1, pre = i;
        if (s[i] == '1') {
            up = down + 1;
            down = 0;
    } else {
            down += (n - now);
            up += (now - 1);
        }
        ans = max(ans, max(down, up));
}
    cout << ans << endl;
}


signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}